<?php
session_start();
	require_once("../controller/validation.php");
		connection();
include_once '../controller/functions.php';

$user = new User();


if($_SESSION['user_type'] != 'admin') {
	//User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	header("location:login_r.php");

}


?>
<script type="text/javascript" src="../javascripts/jquery.js"></script>
	<script type="text/javascript" src="../javascripts/validation.js"></script>
    <script type="text/javascript" src="../javascripts/jquery-ui-1.7.2.custom.min.js"> </script>
 <script type="text/javascript">
	$(function(){
				$('#datepicker').datepicker({
					dateFormat:'dd/mm/yy',
					changeMonth: true,
					changeYear: true,
					yearRange: '-90:+0',
					maxDate: '+0'
				});
	});
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Registration</title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
 	<link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/jquery-ui-1.7.2.custom.css" type="text/css" charset="utf-8" />
</head>
<body>

 <div id="page">
<div id="wrapper">
        	
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
    <!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu.php');
	echo '</div>';
    echo '</div>';
	?>

 <div id="header_in"> <!--open header -->
    <p> </p>
    <? User::showUser(); ?>
    </div>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <div id="chef_ind"> <!--open chef -->
        <div id="welcome"> <!--open welcome -->
          <h2 class="guilded"></h2>
        </div> <!--close welcome-->
        

	<div id="container">
		<h1>Registration process</h1>
		
		<?if( isset($_POST['send']) && (!validateSn($_POST['secName']) ||  !validateSecAd($_POST['secAd']) ||!validateRm($_POST['rmName']) || !validateFname($_POST['fname']) ||  !validateDOB($_POST['bday']) || !validateFname($_POST['sex']) || !validateMname($_POST['mname']) || !validateLname($_POST['lname']) || !validateEmail($_POST['email']) ) ):?>
				<div id="error">
					<ul>
						<?if(!validateFname($_POST['fname'])):?>
							<li><strong>Invalid Firstname:</strong> We want Firstname with more than 3 letters!</li>
						<?endif?>
                        <?if(!validateMname($_POST['mname'])):?>
							<li><strong>Invalid Middlename:</strong> We want Firstname with more than 3 letters!</li>
						<?endif?>
                        <?if(!validateLname($_POST['lname'])):?>
							<li><strong>Invalid Lastname:</strong> We want Firstname with more than 3 letters!</li>
						<?endif?>
                        <?if(!validateSn($_POST['secName'])):?>
							<li><strong>Invalid secName:</strong> We want secName with more than 3 letters!</li>
						<?endif?>
                          <?if(!validateSecAd($_POST['secAd'])):?>
							<li><strong>Invalid secName:</strong> We want secName with more than 3 letters!</li>
						<?endif?>
                         <?if(!validateRm($_POST['rmName'])):?>
							<li><strong>Invalid rmName:</strong> We want rmName with more than 3 letters!</li>
						<?endif?>
                        <?if(!validateSex($_POST['sex'])):?>
							<li><strong>Invalid Gender:</strong>Please Select Gender!</li>
						<?endif?>
                      <?if(!validateDOB($_POST['bday'])):?>
			<li>Type a valid Date Of Birth, dd/mm/yyyy !</li>
					<?endif?>  
						<?if(!validateEmail($_POST['email'])):?>
							<li><strong>Invalid E-mail:</strong> Hey Stop! Please type a valid e-mail please :P</li>
						<?endif?>
                        
					</ul>
				</div>
		<!--Registration for students -->
				
				<? elseif(isset($_POST['send'])):
				$password = mt_rand() . mt_rand() . mt_rand();
            		$query = sprintf("INSERT INTO tblUser(fname,mname,lname,birthdate,gender,email,password,user_type,datejoin,status) VALUES('$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[bday]','$_POST[sex]','$_POST[email]','$password','student',NOW(),0 );", mysql_real_escape_string(strip_tags($user)), mysql_real_escape_string(strip_tags($message)));
	$res = @mysql_query($query);
	
		$query1 = sprintf("INSERT INTO tblsection(sectionName,roomName,sectionAdviser) VALUES('$_POST[secName]','$_POST[rmName]','$_POST[secAd]');", mysql_real_escape_string(strip_tags($user)), mysql_real_escape_string(strip_tags($message)));
	$res1 = @mysql_query($query1);
	
	if($res == 1 && $res1 == 1){
		
		echo '<div id="okay">Done,Thanks !</div>';
	}
	else{
		echo '<div id="error">Error occured while saving!</div>';
	}  
	
	if(!$res)
		die("Error: ".mysql_error());
	else
		return $res;
			
            ?>
            
            <div id="error" class="valid">
					<ul>
						<li><strong>Congratulations!</strong> All fields are OK ;)</li>
					</ul>
				</div>	
		<?endif?>

		<form method="post" id="customForm" action="">
			<div>
				<label for="fname">Firstname</label>
				<input id="fname" name="fname" type="text" />
				<span id="fnameInfo">What's your Firstname?</span>
			</div>
            <div>
            
				<label for="mname">Middlename</label>
				<input id="mname" name="mname" type="text" />
				<span id="mnameInfo">What's your Middlename?</span>
			</div>
            <div>
            
				<label for="lname">Lastname</label>
				<input id="lname" name="lname" type="text" />
				<span id="lnameInfo">What's your Lastname?</span>
			</div>
            <div>
            
				<label for="secName">secName</label>
				<input id="secName" name="secName" type="text" />
				<span id="secNameInfo">What's your secName?</span>
			</div>
             <div>
            
				<label for="rmName">Room Name</label>
				<input id="rmName" name="rmName" type="text" />
				<span id="rmNameInfo">What's your rmName?</span>
			</div>
             <div>
            
				<label for="secAd">Sec AD</label>
				<input id="secAd" name="secAd" type="text" />
				<span id="rsecAdInfo">What's your secAd?</span>
			</div>
            <div>
          
				 <label for="bday">Birthday</label>
				<input name="bday" type="text" size="10" id="datepicker" />
				<span id="bdayInfo">What's your is your birthday?</span>
            </div>
            
             <div>
            
            
				<label for="sex">Gender</label>
			<input type="radio" name="sex" value="male" />
       	Male <p> </p>
       	<input type="radio" name="sex" value="female"  />
       	Female	
				<span id="sexInfo">She or He?</span>
			</div>
			<div>
				<label for="email">E-mail</label>
				<input id="email" name="email" type="text" />
				<span id="emailInfo">Valid E-mail please, you will need it to log in!</span>
			</div>
			<div>
				<input id="send" name="send" type="submit" value="Send" />
			</div>
		</form>
	</div>
      <!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->

	
</body>
</html>